//package com.baibei.module.stock.basic;
//
//import android.content.Context;
//import android.os.Bundle;
//import android.support.annotation.Nullable;
//import android.support.v4.content.ContextCompat;
//import android.util.Log;
//import android.view.MotionEvent;
//import android.view.View;
//import android.widget.TextView;
//
//import com.baibei.model.MinuteEntry;
//import com.baibei.model.ProductInfo;
//import com.baibei.model.QuotationInfo;
//import com.baibei.module.LazyLoadFragment;
//import com.baibei.module.stock.OnChartGestureListener2;
//import com.baibei.module.stock.R;
//import com.baibei.module.stock.StockLayout;
//import com.baibei.module.stock.theme.MinuteChartTheme;
//import com.baibei.quotation.event.QuotationPendingEvent;
//import com.baibei.widget.stock.*;
//import com.baibei.widget.stock.MinuteChart;
//import com.github.mikephil.charting.components.LimitLine;
//import com.github.mikephil.charting.data.Entry;
//import com.github.mikephil.charting.highlight.Highlight;
//import com.github.mikephil.charting.listener.ChartTouchListener;
//import com.github.mikephil.charting.listener.OnChartGestureListener;
//import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
//import com.rae.swift.Rx;
//
//import org.greenrobot.eventbus.EventBus;
//import org.greenrobot.eventbus.Subscribe;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import static android.content.ContentValues.TAG;
//
///**
// * 基础分时图
// * Created by ChenRui on 2017/5/22 0022 10:08.
// */
//public class BasicMinuteFragment extends LazyLoadFragment implements StockMinuteContract.View {
//    protected com.baibei.widget.stock.MinuteChart mMinuteChart;
//    //    protected RaeBarChart mVolumeChart;
//    protected TextView mMarkerViewText;
//    protected StockMinuteContract.Presenter mPresenter;
//    //    protected RaeChartContainer mRaeChartContainer;
//    protected RaeMarkerView mLeftMarkerView;
//    private StockLayout mStockLayout;
//
//    private final List<String> xValues = new ArrayList<>(); // ChartDataConverter.getXAisLabels("09:00", "15:00", true); //;
//    private final List<Entry> yValues = new ArrayList<>();
//    private int mPosition = 0;
//    private View mContentView;
//    private LimitLine limitLine;
//    private RaeMarkerView mXMarkerView;
//    private TextView mXMarkerViewText;
////    private final List<BarEntry> volumeValues = new ArrayList<>(); // 成交量数据
//
//    @Override
//    public int getLayoutId(Bundle savedInstanceState) {
//        return R.layout.fm_stock_timeline_simple;
//    }
//
//    @Override
//    public void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        mPresenter = inject(StockMinuteContract.Presenter.class);
//        EventBus.getDefault().register(this);
//    }
//
//    @Override
//    public void onDestroyView() {
//        clearData();
//        super.onDestroyView();
//    }
//
//    @Override
//    public void onDestroy() {
//        super.onDestroy();
//        mPresenter.destroy();
//        EventBus.getDefault().unregister(this);
//    }
//
//    @Override
//    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
//        super.onViewCreated(view, savedInstanceState);
//        mContentView = view.getRootView();
//
//        mStockLayout = (StockLayout) view.findViewById(R.id.layout_stock);
//        mMinuteChart = (MinuteChart) view.findViewById(R.id.chart_timeline);
//        // 设置主题
//        mMinuteChart.setTheme(new MinuteChartTheme());
//
////        // 空白处点击
////        mStockLayout.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                // 休市前半个小时状态
////                if (ProductProvider.isTradePending()) {
////                    return;
////                }
////                AppRouter.routeToLandscapeChart(getContext(), mMinuteChart.getChartType().name(), null);
////            }
////        });
//
//        // 分时图标记图
//        mLeftMarkerView = new RaeMarkerView(getContext(), R.layout.stock_timeline_marker_view, RaeMarkerView.MarkerViewPosition.HORIZONTAL);
//        mMarkerViewText = (TextView) mLeftMarkerView.findViewById(R.id.tv_marker_view_text);
//        mLeftMarkerView.setIndicatorDrawable(ContextCompat.getDrawable(getContext(), R.drawable.icon_stock_indicator));
//        mMinuteChart.setDrawMarkers(true);
//        mMinuteChart.setMarker(mLeftMarkerView);
//
//        // 分时图标记图 - X坐标
//        mXMarkerView = new RaeMarkerView(getContext(), R.layout.stock_timeline_marker_view, RaeMarkerView.MarkerViewPosition.VERTICAL_BOTTOM);
//        mXMarkerViewText = (TextView) mXMarkerView.findViewById(R.id.tv_marker_view_text);
//        mMinuteChart.setDrawMarkers(true);
//        mMinuteChart.addMarker(mXMarkerView);
//
//
//        // 标记监听
//        mMinuteChart.addOnChartValueSelectedListener(new OnChartValueSelectedListener() {
//            @Override
//            public void onValueSelected(Entry e, Highlight h) {
//                mMarkerViewText.setText(mMinuteChart.getAxisLeftLabel(e.getY()));
//                mXMarkerViewText.setText(mMinuteChart.getXAxisLabel(e.getX()));
//            }
//
//            @Override
//            public void onNothingSelected() {
//                mMarkerViewText.setText("");
//            }
//        });
//
//        if (mOnChartGestureListener != null) {
//            mMinuteChart.setOnChartGestureListener(new OnChartGestureListener() {
//                @Override
//                public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
//                    if (mOnChartGestureListener != null) {
//                        mOnChartGestureListener.onChartGestureStart(mMinuteChart, me, lastPerformedGesture);
//                    }
//                }
//
//                @Override
//                public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
//                    if (mOnChartGestureListener != null) {
//                        mOnChartGestureListener.onChartGestureEnd(mMinuteChart, me, lastPerformedGesture);
//                    }
//                }
//
//                @Override
//                public void onChartLongPressed(MotionEvent me) {
//                    if (mOnChartGestureListener != null) {
//                        mOnChartGestureListener.onChartLongPressed(mMinuteChart, me);
//                    }
//                }
//
//                @Override
//                public void onChartDoubleTapped(MotionEvent me) {
//
//                }
//
//                @Override
//                public void onChartSingleTapped(MotionEvent me) {
//
//                }
//
//                @Override
//                public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
//
//                }
//
//                @Override
//                public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
//
//                }
//
//                @Override
//                public void onChartTranslate(MotionEvent me, float dX, float dY) {
//
//                }
//            });
//        }
//    }
//
//    /**
//     * 监听手势回调
//     */
//    private OnChartGestureListener2 mOnChartGestureListener;
//
//    @Override
//    public void onAttach(Context context) {
//        super.onAttach(context);
//        if (context instanceof OnChartGestureListener2) {
//            mOnChartGestureListener = (OnChartGestureListener2) context;
//        }
//    }
//
//
//    @Override
//    public void setUserVisibleHint(boolean isVisibleToUser) {
//        if (isInitData) {
//            if (isVisibleToUser) {
//                mPresenter.registerMarketStatus();
//            } else {
//                mPresenter.unRegisterMarketStatus();
//                mPresenter.stopInterval();
//            }
//        } else {
//            super.setUserVisibleHint(isVisibleToUser);
//        }
//    }
//
//
//    @Override
//    public void lazyLoad() {
//        loadData();
//    }
//
//    /**
//     * 清除数据
//     */
//    private void clearData() {
//        xValues.clear();
//        yValues.clear();
//        mMinuteChart.clear();
//    }
//
//    /**
//     * 加载数据
//     */
//    protected void loadData() {
//
////        // 是否开市前半个小时
////        if (ProductProvider.isTradePending()) {
////            mStockLayout.dismissLoading();
////            onEvent(new QuotationPendingEvent(!ProductProvider.isTradePending()));
////            return;
////        }
//        mPresenter.start();
//        mStockLayout.showLoading();
//    }
//
////    @Override
////    public String getProductId() {
////        return getArguments().getString("productInfo");
////    }
//
//    @Override
//    public String getProductInfo() {
//        return getArguments().getString("productInfo");
//    }
//
//    @Override
//    public void onLoadChartDataFailed(String type, String message) {
//        mStockLayout.dismissLoading();
//        mStockLayout.setEmpty(true);
//        mMinuteChart.setNoDataText(message);
//        mMinuteChart.clear();
//        mMinuteChart.invalidate();
//    }
//
//
//    @Override
//    public void onLoadMinuteChartData(List<MinuteEntry> minuteEntries, Long limitValue) {
//        if (!isVisible()) return;
//        if (Rx.isEmpty(minuteEntries)) {
//            mStockLayout.dismissLoading();
//            mStockLayout.setEmpty(true);
//            return;
//        }
//
//        mStockLayout.dismissLoading();
//        mStockLayout.setEmpty(false);
//
////        // 是否开市前半个小时
////        if (ProductProvider.isTradePending()) {
////            mStockLayout.setIsTrade(false);
////            return;
////        }
//
//        // 清除之前的数据
//        clearData();
//
//        // 转换数据
//        int count = minuteEntries.size();
//        for (int i = 0; i < count; i++) {
//            MinuteEntry entry = minuteEntries.get(i);
//            xValues.add(entry.getTime());
//            yValues.add(new Entry(i, entry.getPrice()));
//        }
//        if (xValues.size() <  60 * 18) {
//            for (int i = 0; i < 60 * 18 - count; i++) {
//                xValues.add("");
//            }
//        }
//
//        mMinuteChart.setData(xValues, yValues, limitValue);
//
//    }
//
//    @Override
//    public void onTradeOutTime() {
//        mStockLayout.dismissLoading();
//        mStockLayout.setEmpty(false);
//        mMinuteChart.setNoDataTextSize(20);
//        mMinuteChart.setNoDataText("休市中");
//        mMinuteChart.clear();
//    }
//
//
//    @Subscribe
//    public void onEvent(QuotationPendingEvent event) {
//        if (event.isOpen) {
//            loadData();
//        }
//        mStockLayout.setIsTrade(event.isOpen);
//    }
//
//    @Override
//    public void onLoadQuotation(QuotationInfo quotation) {
//    }
//
//    @Override
//    public void onQuotationPending() {
//    }
//
//
//    public void setClosePrice(double closePrice) {
//        if (this.isDetached() || this.mMinuteChart == null) return;
//        // 暂时不处理这个业务需求
////        this.setLimitValue((float) closePrice);
//    }
//
////    public void setLimitValue(float limitValue) {
////        if (limitLine != null) return;
////        this.mMinuteChart.getAxisLeft().removeAllLimitLines();
////        limitLine = new LimitLine(limitValue, (String) null);
////        limitLine.setLineWidth(1.0F);
////        limitLine.enableDashedLine(8.0F, 8.0F, 0.0F);
////        limitLine.setLineColor(Color.parseColor("#303030"));
////        limitLine.setLabelPosition(LimitLine.LimitLabelPosition.RIGHT_TOP);
////        this.mMinuteChart.getAxisLeft().addLimitLine(limitLine);
////        this.mMinuteChart.invalidate();
////    }
//}

//package com.baibei.module.stock.basic;
//
//import android.os.Bundle;
//import android.support.annotation.Nullable;
//import android.support.v4.content.ContextCompat;
//import android.util.Log;
//import android.view.View;
//import android.widget.TextView;
//
//import com.baibei.model.MinuteEntry;
//import com.baibei.model.ProductInfo;
//import com.baibei.model.QuotationInfo;
//import com.baibei.module.LazyLoadFragment;
//import com.baibei.module.stock.R;
//import com.baibei.module.stock.StockLayout;
//import com.baibei.module.stock.theme.MinuteChartTheme;
//import com.baibei.quotation.event.QuotationPendingEvent;
//
//import com.baibei.widget.stock.RaeMarkerView;
//import com.github.mikephil.charting.components.LimitLine;
//import com.github.mikephil.charting.data.Entry;
//import com.github.mikephil.charting.highlight.Highlight;
//import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
//import com.rae.swift.Rx;
//
//import org.greenrobot.eventbus.EventBus;
//import org.greenrobot.eventbus.Subscribe;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * 基础分时图
// * Created by ChenRui on 2017/5/22 0022 10:08.
// */
//public class BasicMinuteFragment extends LazyLoadFragment implements StockMinuteContract.View {
//    protected MinuteChart mMinuteChart;
//    //    protected RaeBarChart mVolumeChart;
//    protected TextView mMarkerViewText;
//    protected StockMinuteContract.Presenter mPresenter;
//    //    protected RaeChartContainer mRaeChartContainer;
//    protected RaeMarkerView mLeftMarkerView;
//    private StockLayout mStockLayout;
//
//    private final List<String> xValues = new ArrayList<>(); // ChartDataConverter.getXAisLabels("09:00", "15:00", true); //;
//    private final List<Entry> yValues = new ArrayList<>();
//    private int mPosition = 0;
//    private View mContentView;
//    private LimitLine limitLine;
//    private RaeMarkerView mXMarkerView;
//    private TextView mXMarkerViewText;
////    private final List<BarEntry> volumeValues = new ArrayList<>(); // 成交量数据
//
//    @Override
//    public int getLayoutId(Bundle savedInstanceState) {
//        return R.layout.fm_stock_timeline_simple;
//    }
//
//    @Override
//    public void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        mPresenter = inject(StockMinuteContract.Presenter.class);
//        EventBus.getDefault().register(this);
//    }
//
//    @Override
//    public void onDestroyView() {
//        clearData();
//        super.onDestroyView();
//    }
//
//    @Override
//    public void onDestroy() {
//        super.onDestroy();
//        mPresenter.destroy();
//        EventBus.getDefault().unregister(this);
//    }
//
//    @Override
//    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
//        super.onViewCreated(view, savedInstanceState);
//        mContentView = view.getRootView();
//
//        mStockLayout = (StockLayout) view.findViewById(R.id.layout_stock);
//        mMinuteChart = (MinuteChart) view.findViewById(R.id.chart_timeline);
//        // 设置主题
//        mMinuteChart.setTheme(new MinuteChartTheme());
//
////        // 空白处点击
////        mStockLayout.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                // 休市前半个小时状态
////                if (ProductProvider.isTradePending()) {
////                    return;
////                }
////                AppRouter.routeToLandscapeChart(getContext(), mMinuteChart.getChartType().name(), null);
////            }
////        });
//
//        // 分时图标记图
//        mLeftMarkerView = new RaeMarkerView(getContext(), R.layout.stock_timeline_marker_view, RaeMarkerView.MarkerViewPosition.HORIZONTAL);
//        mMarkerViewText = (TextView) mLeftMarkerView.findViewById(R.id.tv_marker_view_text);
//        mLeftMarkerView.setIndicatorDrawable(ContextCompat.getDrawable(getContext(), R.drawable.icon_stock_indicator));
//        mMinuteChart.setDrawMarkers(true);
//        mMinuteChart.setMarker(mLeftMarkerView);
//
//        // 分时图标记图 - X坐标
//        mXMarkerView = new RaeMarkerView(getContext(), R.layout.stock_timeline_marker_view, RaeMarkerView.MarkerViewPosition.VERTICAL_BOTTOM);
//        mXMarkerViewText = (TextView) mXMarkerView.findViewById(R.id.tv_marker_view_text);
//        mMinuteChart.setDrawMarkers(true);
//        mMinuteChart.addMarker(mXMarkerView);
//
//
//        // 标记监听
//        mMinuteChart.addOnChartValueSelectedListener(new OnChartValueSelectedListener() {
//            @Override
//            public void onValueSelected(Entry e, Highlight h) {
//                mMarkerViewText.setText(mMinuteChart.getAxisLeftLabel(e.getY()));
//                mXMarkerViewText.setText(mMinuteChart.getXAxisLabel(e.getX()));
//            }
//
//            @Override
//            public void onNothingSelected() {
//                mMarkerViewText.setText("");
//            }
//        });
//
//
//    }
//
//
//    @Override
//    public void setUserVisibleHint(boolean isVisibleToUser) {
//        if (isInitData) {
//            if (isVisibleToUser) {
//                mPresenter.registerMarketStatus();
//            } else {
//                mPresenter.unRegisterMarketStatus();
//                mPresenter.stopInterval();
//            }
//        } else {
//            super.setUserVisibleHint(isVisibleToUser);
//        }
//    }
//
//
//    @Override
//    public void lazyLoad() {
//        loadData();
//    }
//
//    /**
//     * 清除数据
//     */
//    private void clearData() {
//        xValues.clear();
//        yValues.clear();
//        mMinuteChart.clear();
//    }
//
//    /**
//     * 加载数据
//     */
//    protected void loadData() {
//
////        // 是否开市前半个小时
////        if (ProductProvider.isTradePending()) {
////            mStockLayout.dismissLoading();
////            onEvent(new QuotationPendingEvent(!ProductProvider.isTradePending()));
////            return;
////        }
//        mPresenter.start();
//        mStockLayout.showLoading();
//    }
//
//    @Override
//    public String getProductInfo() {
//
//        return getArguments().getString("productInfo");
//    }
//
//    @Override
//    public void onLoadChartDataFailed(String type, String message) {
//        mStockLayout.dismissLoading();
//        mStockLayout.setEmpty(true);
//        mMinuteChart.setNoDataText(message);
//        mMinuteChart.clear();
//        mMinuteChart.invalidate();
//    }
//
//
//    @Override
//    public void onLoadMinuteChartData(List<MinuteEntry> minuteEntries, Long limitValue) {
//        if (!isVisible()) return;
//        if (Rx.isEmpty(minuteEntries)) {
//            mStockLayout.dismissLoading();
//            mStockLayout.setEmpty(true);
//            return;
//        }
//
//        mStockLayout.dismissLoading();
//        mStockLayout.setEmpty(false);
//
////        // 是否开市前半个小时
////        if (ProductProvider.isTradePending()) {
////            mStockLayout.setIsTrade(false);
////            return;
////        }
//
//        // 清除之前的数据
//        clearData();
//
//        // 转换数据
//        int count = minuteEntries.size();
//        for (int i = 0; i < count; i++) {
//            MinuteEntry entry = minuteEntries.get(i);
//            xValues.add(entry.getTime());
//            yValues.add(new Entry(i, entry.getPrice()));
//        }
//        mMinuteChart.setData(xValues, yValues, limitValue);
//
//    }
//
//    @Override
//    public void onTradeOutTime() {
//        mStockLayout.dismissLoading();
//        mStockLayout.setEmpty(false);
//        mMinuteChart.setNoDataTextSize(20);
//        mMinuteChart.setNoDataText("休市中");
//        mMinuteChart.clear();
//    }
//
//
//    @Subscribe
//    public void onEvent(QuotationPendingEvent event) {
//        if (event.isOpen) {
//            loadData();
//        }
//        mStockLayout.setIsTrade(event.isOpen);
//    }
//
//    @Override
//    public void onLoadQuotation(QuotationInfo quotation) {
//    }
//
//    @Override
//    public void onQuotationPending() {
//    }
//
//
//    public void setClosePrice(double closePrice) {
//        if (this.isDetached() || this.mMinuteChart == null) return;
//        // 暂时不处理这个业务需求
////        this.setLimitValue((float) closePrice);
//    }
//
////    public void setLimitValue(float limitValue) {
////        if (limitLine != null) return;
////        this.mMinuteChart.getAxisLeft().removeAllLimitLines();
////        limitLine = new LimitLine(limitValue, (String) null);
////        limitLine.setLineWidth(1.0F);
////        limitLine.enableDashedLine(8.0F, 8.0F, 0.0F);
////        limitLine.setLineColor(Color.parseColor("#303030"));
////        limitLine.setLabelPosition(LimitLine.LimitLabelPosition.RIGHT_TOP);
////        this.mMinuteChart.getAxisLeft().addLimitLine(limitLine);
////        this.mMinuteChart.invalidate();
////    }
//}
package com.baibei.module.stock.basic;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.TextView;

import com.baibei.model.MinuteEntry;
import com.baibei.model.ProductInfo;
import com.baibei.model.QuotationInfo;
import com.baibei.module.LazyLoadFragment;
import com.baibei.module.stock.R;
import com.baibei.module.stock.StockLayout;
import com.baibei.module.stock.theme.MinuteChartTheme;
import com.baibei.quotation.event.QuotationPendingEvent;
import com.baibei.widget.stock.MinuteChart;
import com.baibei.widget.stock.RaeMarkerView;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.rae.swift.Rx;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.List;

/**
 * 基础分时图
 * Created by ChenRui on 2017/5/22 0022 10:08.
 */
public class BasicMinuteFragment extends LazyLoadFragment implements StockMinuteContract.View {
    protected MinuteChart mMinuteChart;
    //    protected RaeBarChart mVolumeChart;
    protected TextView mMarkerViewText;
    protected StockMinuteContract.Presenter mPresenter;
    //    protected RaeChartContainer mRaeChartContainer;
    protected RaeMarkerView mLeftMarkerView;
    private StockLayout mStockLayout;

    private final List<String> xValues = new ArrayList<>(); // ChartDataConverter.getXAisLabels("09:00", "15:00", true); //;
    private final List<Entry> yValues = new ArrayList<>();
    private int mPosition = 0;
    private View mContentView;
    private LimitLine limitLine;
    private RaeMarkerView mXMarkerView;
    private TextView mXMarkerViewText;
//    private final List<BarEntry> volumeValues = new ArrayList<>(); // 成交量数据

    @Override
    public int getLayoutId(Bundle savedInstanceState) {
        return R.layout.fm_stock_timeline_simple;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = inject(StockMinuteContract.Presenter.class);
        EventBus.getDefault().register(this);
    }

    @Override
    public void onDestroyView() {
        clearData();
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.destroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mContentView = view.getRootView();

        mStockLayout = (StockLayout) view.findViewById(R.id.layout_stock);
        mMinuteChart = (MinuteChart) view.findViewById(R.id.chart_timeline);
        // 设置主题
        mMinuteChart.setTheme(new MinuteChartTheme());

//        // 空白处点击
//        mStockLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                // 休市前半个小时状态
//                if (ProductProvider.isTradePending()) {
//                    return;
//                }
//                AppRouter.routeToLandscapeChart(getContext(), mMinuteChart.getChartType().name(), null);
//            }
//        });

        // 分时图标记图
        mLeftMarkerView = new RaeMarkerView(getContext(), R.layout.stock_timeline_marker_view, RaeMarkerView.MarkerViewPosition.HORIZONTAL);
        mMarkerViewText = (TextView) mLeftMarkerView.findViewById(R.id.tv_marker_view_text);
        mLeftMarkerView.setIndicatorDrawable(ContextCompat.getDrawable(getContext(), R.drawable.icon_stock_indicator));
        mMinuteChart.setDrawMarkers(true);
        mMinuteChart.setMarker(mLeftMarkerView);

        // 分时图标记图 - X坐标
        mXMarkerView = new RaeMarkerView(getContext(), R.layout.stock_timeline_marker_view, RaeMarkerView.MarkerViewPosition.VERTICAL_BOTTOM);
        mXMarkerViewText = (TextView) mXMarkerView.findViewById(R.id.tv_marker_view_text);
        mMinuteChart.setDrawMarkers(true);
        mMinuteChart.addMarker(mXMarkerView);


        // 标记监听
        mMinuteChart.addOnChartValueSelectedListener(new OnChartValueSelectedListener() {
            @Override
            public void onValueSelected(Entry e, Highlight h) {
                mMarkerViewText.setText(mMinuteChart.getAxisLeftLabel(e.getY()));
                mXMarkerViewText.setText(mMinuteChart.getXAxisLabel(e.getX()));
            }

            @Override
            public void onNothingSelected() {
                mMarkerViewText.setText("");
            }
        });


    }


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        if (isInitData) {
            if (isVisibleToUser) {
                mPresenter.registerMarketStatus();
            } else {
                mPresenter.unRegisterMarketStatus();
                mPresenter.stopInterval();
            }
        } else {
            super.setUserVisibleHint(isVisibleToUser);
        }
    }


    @Override
    public void lazyLoad() {
        loadData();
    }

    /**
     * 清除数据
     */
    private void clearData() {
        xValues.clear();
        yValues.clear();
        mMinuteChart.clear();
    }

    /**
     * 加载数据
     */
    protected void loadData() {

//        // 是否开市前半个小时
//        if (ProductProvider.isTradePending()) {
//            mStockLayout.dismissLoading();
//            onEvent(new QuotationPendingEvent(!ProductProvider.isTradePending()));
//            return;
//        }
        mPresenter.start();
        mStockLayout.showLoading();
    }

    @Override
    public String getProductInfo() {
        return getArguments().getString("productInfo");
    }

    @Override
    public void onLoadChartDataFailed(String type, String message) {
        mStockLayout.dismissLoading();
        mStockLayout.setEmpty(true);
        mMinuteChart.setNoDataText(message);
        mMinuteChart.clear();
        mMinuteChart.invalidate();
    }


    @Override
    public void onLoadMinuteChartData(List<MinuteEntry> minuteEntries, Long limitValue) {
        if (!isVisible()) return;
        if (Rx.isEmpty(minuteEntries)) {
            mStockLayout.dismissLoading();
            mStockLayout.setEmpty(true);
            return;
        }

        mStockLayout.dismissLoading();
        mStockLayout.setEmpty(false);

//        // 是否开市前半个小时
//        if (ProductProvider.isTradePending()) {
//            mStockLayout.setIsTrade(false);
//            return;
//        }

        // 清除之前的数据
        clearData();

        // 转换数据
        int count = minuteEntries.size();
        for (int i = 0; i < count; i++) {
            MinuteEntry entry = minuteEntries.get(i);
            xValues.add(entry.getTime());
            yValues.add(new Entry(i, entry.getPrice()));
        }

        mMinuteChart.setData(xValues, yValues, limitValue);

    }

    @Override
    public void onTradeOutTime() {
        mStockLayout.dismissLoading();
        mStockLayout.setEmpty(false);
        mMinuteChart.setNoDataTextSize(20);
        mMinuteChart.setNoDataText("休市中");
        mMinuteChart.clear();
    }


    @Subscribe
    public void onEvent(QuotationPendingEvent event) {
        if (event.isOpen) {
            loadData();
        }
        mStockLayout.setIsTrade(event.isOpen);
    }

    @Override
    public void onLoadQuotation(QuotationInfo quotation) {
    }

    @Override
    public void onQuotationPending() {
    }


    public void setClosePrice(double closePrice) {
        if (this.isDetached() || this.mMinuteChart == null) return;
        // 暂时不处理这个业务需求
//        this.setLimitValue((float) closePrice);
    }

//    public void setLimitValue(float limitValue) {
//        if (limitLine != null) return;
//        this.mMinuteChart.getAxisLeft().removeAllLimitLines();
//        limitLine = new LimitLine(limitValue, (String) null);
//        limitLine.setLineWidth(1.0F);
//        limitLine.enableDashedLine(8.0F, 8.0F, 0.0F);
//        limitLine.setLineColor(Color.parseColor("#303030"));
//        limitLine.setLabelPosition(LimitLine.LimitLabelPosition.RIGHT_TOP);
//        this.mMinuteChart.getAxisLeft().addLimitLine(limitLine);
//        this.mMinuteChart.invalidate();
//    }
}
